<template lang="">
  <div>
    <!-- 搜索 -->

    <!-- <QueryForm :searchForm="searchForm" :items="items" @search="search" @list="list"></QueryForm> -->
    <!-- 操作按钮区域 -->
    <!-- <div class="btn-panel">
      <el-button type="danger" size="small" icon="el-icon-delete" @click="deleteMany">批量删除</el-button>
    </div> -->
    <!-- 表格 -->
    <Table1 ref="multipleTable" :tableData="tableData" :tableCols="tableCols" :isEdit="false" @deleteUser="del">

      <template v-if="scope.data.post.name!='' ||scope.data.post.name!=null" slot="slot_post" slot-scope="scope">
        {{scope.data.post.name}}
      </template>
      <template v-if="scope.data.company.name!='' || scope.data.company.name!=null" slot="slot_company"
        slot-scope="scope">
  {{scope.data.company.name}}
</template>
    </Table1>
    <div style="margin-top: 20px">
      <!-- 分页组件 -->
      <Page1 :pages="pages" :total="total" @handleCurrentChange="handleCurrentChange"
        @handleSizeChange="handleSizeChange"></Page1>


    </div>
  </div>
</template>
<script>
import Table1 from '@/components/Table1'
import Page1 from '@/components/Page1'
import QueryForm from '@/components/QueryForm'
import local from '@/store/local.js'

export default {
  name: 'favor',
  components: {
    Table1,
    Page1,
    // QueryForm
  },
  data() {
    return {
      // 表格
      total: 0,
      pages: 1,
      currentPage: 1,
      size: 10,
      tableData: [],

      tableCols: [
        {
          prop: 'id',
          label: 'ID',
          width: 80,
        },
        {
          prop: 'post_id',
          label: '职位',
          slot: 'slot_post',
        },
        {
          prop: 'company_id',
          label: '公司',
          slot: 'slot_company',
        },
        {
          prop: 'favor_date',
          label: '收藏日期',
        },
      ],
    }
  },

  created() {},
  mounted() {
    let id = local.getUserInfo().id
    this.list({
      student_id: id,
    })
  },
  methods: {
    //初始化
    list(param) {
      this.postRequest('/favor/page', {
        ...param,
      }).then((res) => {
        console.log(res, '分页查询的数据')
        this.tableData = res.data
        this.total = res.total
        this.pages = res.pages
      })
    },
    // 当前页改变
    handleCurrentChange(page) {
      this.currentPage = page
      this.list()
    },
    // 当前size改变
    handleSizeChange(size) {
      this.size = size
      this.list()
    },

    // 删除
    del() {
      console.log(this.$refs['multipleTable'].data, '删除事件')
      let data = this.$refs['multipleTable'].data
      console.log('删除', data)
      this.$confirm('确定要删除吗', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          this.deleteRequest('/favor/' + data.id).then((res) => {
            if (res.code == 200) {
              console.log(res, '删除=======')
              this.$message.success(res.message)
              this.list()
            } else {
              this.$message.error(res.message)
            }
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除',
          })
        })
    },
  },
}
</script>
<style lang=""></style>